home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.orig.lzh / expire / lowest.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  896b  |  51 lines

  1. /*
  2.  * lowest - print the number of the lowest article in a directory
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <dirent.h>
  8.  
  9. #define    HUGE    999999999L    /* Bigger than any valid article number. */
  10.  
  11. char *progname;
  12.  
  13. /*
  14.  - main - parse arguments and handle options
  15.  */
  16. main(argc, argv)
  17. int argc;
  18. char *argv[];
  19. {
  20.     DIR *d;
  21.     register struct dirent *dp;
  22.     long lowest = HUGE;
  23.     long this;
  24.     extern long atol();
  25.  
  26.     progname = argv[0];
  27.  
  28.     if (argc != 2) {
  29.         fprintf(stderr, "usage: %s directory\n", progname);
  30.         exit(2);
  31.     }
  32.  
  33.     d = opendir(argv[1]);
  34.     if (d == NULL) {
  35.         fprintf(stderr, "%s: can't read directory %s\n", progname,
  36.                                 argv[1]);
  37.         exit(1);
  38.     }
  39.     while ((dp = readdir(d)) != NULL) {
  40.         if (strspn(dp->d_name, "0123456789") == strlen(dp->d_name)) {
  41.             this = atol(dp->d_name);
  42.             if (this < lowest)
  43.                 lowest = this;
  44.         }
  45.     }
  46.     closedir(d);
  47.  
  48.     if (lowest != HUGE)
  49.         printf("%ld\n", lowest);
  50. }
  51.